﻿using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Swifter.Json;
using Swifter.RW;

namespace CKS.Core.Framework

//https://www.cnblogs.com/mzflog/p/14875290.html
{
    public static partial class Ext
    {
        public static string ToJson(this object obj)
        {
          
            return JsonFormatter.SerializeObject(obj);
        }

        public static object ToJson(this string Json)
        {
            return Json == null ? null : JsonConvert.DeserializeObject(Json);
        }

        public static JObject ToJObject(this string Json)
        {

            return Json.IsEmpty() ? JObject.Parse("{}") : JObject.Parse(Json.Replace("&nbsp;", ""));
        }
        public static JArray ToJArray(this string Json)
        {

            return Json.IsEmpty() ? JArray.Parse("[]") : JArray.Parse(Json.Replace("&nbsp;", ""));
        }
    }
}
